﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace JeremiXnaGame
{
    [Serializable()]
    public class Settings
    {
        public string DefaultFont = "Fonts/Default";
        public string PlayerName = "Unnamed";
        public bool IsMouseVisible = false;
        public bool IsFixedTimeStep = true;
        public bool ClipCursor = false;
        public bool EnableSound = true;
        public bool ShowPathGraph = false;
        public bool RevealMap = false;
        public double GameSpeed = 1;
        public bool SkipMenu = true;

        public int ScreenWidth = 960;
        public int ScreenHeight = 600;
        public bool Fullscreen = false;
        public bool ShadowEnabled = true;

        public int MinHeightAboveGround = 50;
        public int DefaultHeightAboveGround = 100;
        public int MaxHeightAboveGround = 180;
        public float WheelFactor = 0.425f;
        public float Sensitivity = 1.5f;
        public float Smoothness = 1.0f;
        public float MinSpeed = 0.04f;
        public float MaxSpeed = 0.2f;


        // We want to trace frame performance, so turn off V'Sync
        #if DEBUG
            public bool VSync = false;
        #else
            public bool VSync = true;
        #endif


        public static Settings DefaultSettings()
        {
            return new Settings();
        }

        public void Save()
        {
            using(FileStream file = new FileStream("Settings.xml", FileMode.Create, FileAccess.ReadWrite))
                new XmlSerializer(typeof(Settings)).Serialize(file, this);
        }

        public static Settings Load()
        {
            if (File.Exists("Settings.xml"))
            {
                using (FileStream file = new FileStream("Settings.xml", FileMode.Open, FileAccess.Read))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Settings));
                    return (Settings)serializer.Deserialize(file);
                }
            }
            else
            {
                Helper.Msg("No Config File found! Loading Default");
                return new Settings();
            }
        }
    }
}
